package com.ltv.xiangqiplugin.views;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import com.ltv.xiangqiplugin.controllers.GameActionControl;

public class GameActionView extends JPanel {
	private static GameActionView instance;
	private JButton rollback;
	
	private GameActionView() {
	    JPanel panel = new JPanel();
	    
	    JButton btn = new JButton("");
	    ImageIcon reverse = new ImageIcon(getClass().getResource("/buttons/reverse.png"));
	    btn.setIcon(reverse);
	    btn.setActionCommand("REVERSE");
	    btn.addActionListener(GameActionControl.getInstance());
	    panel.add(btn);
	    
	    btn = new JButton("");
	    ImageIcon first = new ImageIcon(getClass().getResource("/buttons/first.png"));
	    btn.setIcon(first);
	    btn.setActionCommand("FIRST");
	    btn.addActionListener(GameActionControl.getInstance());
	    panel.add(btn);
	    
	    btn = new JButton("");
	    ImageIcon prev = new ImageIcon(getClass().getResource("/buttons/prev.png"));
	    btn.setIcon(prev);
	    btn.setActionCommand("PREV");
	    btn.addActionListener(GameActionControl.getInstance());
	    panel.add(btn);
	    
	    btn = new JButton("");
	    ImageIcon next = new ImageIcon(getClass().getResource("/buttons/next.png"));
	    btn.setIcon(next);
	    btn.setActionCommand("NEXT");
	    btn.addActionListener(GameActionControl.getInstance());
	    panel.add(btn);
	    
	    btn = new JButton("");
	    ImageIcon last = new ImageIcon(getClass().getResource("/buttons/last.png"));
	    btn.setIcon(last);
	    btn.setActionCommand("LAST");
	    btn.addActionListener(GameActionControl.getInstance());
	    panel.add(btn);
	    
	    ImageIcon refresh = new ImageIcon(getClass().getResource("/buttons/refresh.png"));
	    rollback = new JButton("");
	    rollback.setIcon(refresh);
	    rollback.setEnabled(false);
	    rollback.setActionCommand("ROLLBACK");
	    rollback.addActionListener(GameActionControl.getInstance());
	    panel.add(rollback);
	    
	    this.add(panel);
	    this.add(new JPanel());
	    
	}

	public static GameActionView getInstance() {
		if (instance == null) {
			instance = new GameActionView();
		}
		
		return instance;
	}
	
	public void enableRollbackButton() {
		rollback.setEnabled(true);
	}
	
	public void disableRollbackButton() {
		rollback.setEnabled(false);
	}
	
	public boolean isEnableRollback() {
		return rollback.isEnabled();
	}
}
